// import show_loading from '../../atom-web/show-loading';
// import hide_loading from '../../atom-web/hide-loading';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import s_get from '@dfeidao/atom-web/storage/get';

import remove from '@dfeidao/atom-web/local/remove';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
export default async function a003(fd: IFeidaoAiBrowserComponent) {
	// 删除

	const id = get(fd, '_id');
	if (!id) {
		await error('请选择一条删除数据');
		// fire('zjc-000001', 'ec-001', 'fail', '请选择一条删除数据');
		return;
	} else {
		// const user = await whoami(get_user_info);
		// console.log(user)
		const productid = await s_get('productid');

		// show_loading();
		// const res = await nodejs<{ length: number }>(url, './permissions/pub_role_find1', { role_type_id: id, productid }, false, false);
		const res = await nodejs<{ length: number }>('role-type/zj-000001/s002', { role_type_id: id, productid });
		if (res.length > 0) {
			await error('该角色已被引用，无法删除');
			// fire('zjc-000001', 'ec-001', 'fail', '该角色已被引用，无法删除');
			// hide_loading();
			return;
		} else {
			// const del_res = await nodejs(url, './permissions/role_type_del', { id, productid }, false, false);
			const del_res = await nodejs('role-type/zj-000001/s003', { id, productid });
			// hide_loading();
			if (del_res === 'success') {
				fire('zj-000001', 'ec-002');
				remove(fd, '_id');
				await success('删除成功');
				// fire('zjc-000001', 'ec-001', 'success', '删除成功');
				return;
			} else {
				await error('删除失败');
				// fire('zjc-000001', 'ec-001', 'fail', '删除失败');
				return;
			}
		}
	}
}
